<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>{:SEO('bbs-add','title')}</title>
  <meta name="keywords" content="{:SEO('bbs-add','keywords')}">
  <meta name="description" content="{:SEO('bbs-add','description')}">
  <link href="__ROOT__/{:C('YTATA_TPL_DIR')}/public/css/bbs.css" rel="stylesheet" type="text/css">
  <include file="public:header" />
  
  <div class="qadd">
    <div class="addl">
      <if condition="$Think.session.ytata.uid eq ''">
        <div class="logintip">
          <div class="txt font_yellow">&nbsp;&nbsp;&nbsp;&nbsp;已有账号？登陆后获取特权!</div>
          <div class="txt">
            <div class="btn_green btn_inline_small btn_border J_user_login">立刻登录</div>
          </div>
          <div class="txt font_gray6">用第三方账号登录</div>
          <div class="txt">
            <volist name="oauth_list" id="oauth">
              <a class="uu_api_login_btn {$key}" href="{:U('callback/index',array('mod'=>$key,'type'=>'login'))}"></a>
            </volist>
            <div class="clear"></div>
          </div>
          <div class="clear"></div>
        </div>
      </if>
      
      <form  name="add"  method="post" action="{:RU('bbs/addsave')}">
        <h2>清晰描述您的主题，与众多网友互动交流!</h2>
        <div class="inputbox zindextop">
		
		
          <div class="inputbox" >
          <textarea name="content" id="J_content" cols="" rows="" class="inputs h100" placeholder="请在这里描述你的主题"></textarea>
          <div class="uploadbox">
            <div class="addimg" id="J_upload_btn" name="question_img">图片</div>
            <!--<input type="file" id="j_addmap_file" style="display: none;">-->
            <!--<div class="addmap" id="j_addmap">地点</div>-->
            <div class="clear"></div>
          </div>
		  
        </div>
		
		
          <div class="categorysel J_cat_menu">选择讨论分类</div>
          <input name="category1" id="J_category1" type="hidden" value="0">
          <input name="category2" id="J_category2" type="hidden" value="0">
          <div class="show_menu J_cat_show_menu">
            <ul>
              <ytata:cat listname="li" type="bbs" pid="0"/>
              <volist name="li.list" id="li">
                <li id="{$li.c_id}" title="{$li.c_title}"><span class="liimg"><img src="{$li.c_pic}" /></span>{$li.c_title}</li>
              </volist>
            </ul>
          </div>
        </div>
        
      <!--点击上传图片后图片出现在这里 最多上传3张,未上传下方DIV默认 display:none，非注册用户提问不允许上传图片 -->
        
        <div class="uploadimgbox">
          
          <div class="clear"></div>
        </div>
        
      
        <div class="tagdiv">
          <div class="tagbox">
            <div class="addtag" id="J_addtag">选择标签</div>
            <div class="tip">选择合适的标签可以获得准确回复</div>
          </div>
        </div>
      
        <!--~~~~~~~~~~~~~~ -->
        
        <!--最多可选择3个标签 ,未添加下方DIV默认 display:none -->
        <div class="showtag">
          <div class="tip">你还可以添加<span>3</span>个标签</div>
          <div class="clear"></div>
        </div>
        
        <if condition="$Think.session.ytata.uid eq ''">
          <div class="mb">
            <div class="mbmain">
              <input type="text" class="mbiput" maxlength="11" onKeyUp="if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,'');"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"  placeholder="输入手机号"  name="mobile" >
              
              <input type="text" class="mbiput code" maxlength="11" onKeyUp="if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,'');"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" placeholder="输入验证码"  name="code">
              <div class="mbiput btn J_send_code">获取验证码</div>
            </div>
          </div>
        </if>
        
        <div class="btns">
          <div class="td1">
            <input name="" type="button" id="J_add" value="提交主题" class="btn">
          </div>
          <div class="clear"></div>
        </div>
      </form>
    
    </div>
    
    
    <!--右侧开始 -->
    <div class="addr">
      <div class="help">
        <div class="tit">如何能获得快速准确的回答？</div>
        <div class="td1">1</div>
        <div class="td2">问题标题描述准确；</div>
        <div class="clear"></div>
        <div class="td1">2</div>
        <div class="td2">选择正确发分类和标签；</div>
        <div class="clear"></div>
        <div class="td1">3</div>
        <div class="td2">如果标题描述不清，可使用详细内容继续描述；</div>
        <div class="clear"></div>
        <div class="td1">4</div>
        <div class="td2">适当的增加悬赏会吸引更多用户回答；</div>
        <div class="clear"></div>
      </div>
    </div>
    
    
    <div class="clear"></div>
  </div>
  <include file="public:footer" />
  <!--未登录发布问题 -->
  <script type="text/javascript">
      $(document).ready(function()
      {
          // 添加地图-未使用
          $("#j_addmap").on('click', function () {
              $("#j_addmap_file").trigger('click');
          });
          $("#j_addmap_file").on('change', function(){
              console.log($(this).val());
              return false;
          });
          //提交主题
          $("#J_add").click(function(){
              $(this).val('正在提交......').attr("disabled","disabled");
              content=$('#J_content').val();
              if (content==''){
                  disapperTooltip("remind", "请填写内容");
                  $(this).val('提交主题').removeAttr("disabled");
                  return false;
              }
              else if (content.length < 5) {
                  disapperTooltip("remind", "您的内容过短，请详细填写！");
                  $(this).val('提交主题').removeAttr("disabled");
                  return false;
              }
              category1=$('input[name=category1]').val();
              if (category1=='' || category1=='0'){
                  disapperTooltip("remind", "请选择主题分类！");
                  $(this).val('提交主题').removeAttr("disabled");
                  return false;
              }
          <if condition="$Think.session.ytata.uid eq ''">
              code=$('input[name=code]').val();
              if (code==''){
                  disapperTooltip("remind", "请填写短信验证码！");
                  $(this).val('提交主题').removeAttr("disabled");
                  return false;
              }else{
                  $.getJSON(ajaxURL, { act: "ajax_mobile_code_verify",code:code}, function(json){
                      if (json.status==0){
                          disapperTooltip("remind",json.content);
                          $("#J_add").val('提交主题').removeAttr("disabled");
                          return false;
                      }else if (json.status==1){
                          $("form[name=add]").submit();
                      }else{
                          disapperTooltip("remind","未知错误");
                          $("#J_add").val('提交主题').removeAttr("disabled");
                          return false;
                      }
                  });
              }
          <else />
              $("form[name=add]").submit();
          </if>

          });


          //发送验证码
          $('.J_send_code').live('click',function() {
              btn=$(this);
              if (btn.hasClass('btn_disabled')) return false;
              function settime(countdown) {
                  if (countdown == 0) {
                      btn.removeClass('btn_disabled');
                      btn.text('获取验证码');
                      countdown = {:C('YTATA_SMS_SETTIME')};
                      return;
                  } else {
                      btn.addClass('btn_disabled');
                      btn.text('重新发送' + countdown + '秒');
                      countdown--;
                  }
                  setTimeout(function() {
                      settime(countdown)
                  },1000)
              }
              var mobile=$('input[name=mobile]').val();
              if (mobile.length==''){
                  disapperTooltip("remind",'请填写手机号');
                  return false;
              }
              if (mobile.length!=11){
                  disapperTooltip("remind",'请填写正确的手机号');
                  return false;
              }
              btn.addClass('btn_disabled').html('正在发送中.');
              $.getJSON(ajaxURL, { act:"ajax_send_mobile_code",mobile:mobile,in_user:0}, function(json){
                  if (json.status==0){
                      btn.removeClass('btn_disabled').html('获取验证码');
                      disapperTooltip("remind",json.content);
                  }else if (json.status==1){
                      disapperTooltip("success",json.content);
                      settime({:C('YTATA_SMS_SETTIME')});
                  }else{
                      btn.removeClass('btn_disabled').html('获取验证码');
                      disapperTooltip("remind",json.content);
                  }
              });
          });
      });
  </script>
  <script type="text/javascript">
      var uploadUrl = "{:RU('Upload/img')}";
  </script>
  <script src="__ROOT__/{:C('YTATA_TPL_DIR')}/public/js/ajaxfileupload.js"></script>
  <script src="__ROOT__/{:C('YTATA_TPL_DIR')}/public/js/fileupload.js"></script>
  <script type="text/javascript">
      /********
       /#####
       /#####  图片相关
       /#####
       */
      $(document).ready(function()
      {
          var IMGindex=1;
          var IMGnum=3;//允许上传数量
          var TAGnum=3;//允许TAG添加数量
// 上传图标
          $.upload('#J_upload_btn',{type:'question_img'},function(result){
              if(result.status == 1){;
                  html=htmlSTR(IMGindex);
                  if ($(".uploadimgbox .imgbox").length>=IMGnum){
                      disapperTooltip("remind","最多只能上传"+IMGnum+"张图片");
                      return false;
                  }
                  var imgobj=".uploadimgbox .imgs"+(Number(IMGindex)-1);
                  $(".uploadimgbox").prepend(html).show();
                  $(imgobj).find('a').attr('href',result.content.src);
                  $(imgobj).find('img').attr('src',result.content.src);
                  $(imgobj).find('input').val(result.content.id);
              } else {
                  disapperTooltip("remind", "上传失败："+result.content);
              }
              //生成html
              function htmlSTR(index){
                  html="";
                  html+="<div class=\"imgbox imgs"+index+"\">";
                  html+="<a href=\"#\" target=\"_blank\"><input name=\"img[]\" type=\"hidden\" value=\"#\"><img src=\"#\" border=\"0\" /></a>";
                  html+="<div class=\"del J_img_del\">删除</div>";
                  html+="</div>";
                  IMGindex=index+1;
                  return html;
              }
          });
          //删除上传图片
          $('.J_img_del').live('click',function() {
              $(this).parent(".imgbox").remove();
              if ($(".uploadimgbox .imgbox").length==0) $(".uploadimgbox").hide();
          });
          //修改手机
          $('.J_user_edit_mobile').live('click',function() {
              var YTATADialog = $(this).dialog({
                  title: false,
                  loading: true,
                  footer: false,
                  header: false,
                  border: false,
                  backdrop: false
              });
              $.getJSON(ajaxURL, { act: "ajax_edit_mobile"}, function(json){
                  if (json.status==0){
                      YTATADialog.hide();
                      disapperTooltip("remind", json.content);
                  }else if (json.status==1){
                      YTATADialog.hide();
                      var MDialog = $(this).dialog({
                          title: "修改手机号",
                          content:json.content,
                          footer: true,
                          header: true,
                          border: true,
                          innerPadding: true,
                          backdrop: true,
                          yes: function() {

                              mobile=$("input[name='mobile']").val();
                              code=$("input[name='code']").val();
                              $.getJSON(ajaxURL, { act: "ajax_edit_mobile",mobile:mobile,code:code,edit:"1"}, function(json){
                                  if (json.status==0){
                                      disapperTooltip("remind", json.content);
                                  }else if (json.status==1){
                                      disapperTooltip("success",json.content);
                                      $('.J_user_edit_mobile').text(json.mobile+'[修改]');
                                      $('.modal').remove();
                                      $('.modal_backdrop').remove();
                                  }else{
                                      disapperTooltip("remind","修改失败，未知错误");
                                  }
                              });
                          }
                      });
                      MDialog.setCloseDialog(false);
                  }else{
                      YTATADialog.hide();
                      disapperTooltip("remind","未知错误");
                  }
              });
          });



      });
  </script>
  <script type="text/javascript">
      $(document).ready(function()
      {
          /********
           /#####
           /#####  下拉，分类和悬赏选择
           /#####
           */

//一二级分类切换
      <if condition="C('YTATA_CAT_LEVEL_QUESTION') eq '1'">
          ShowMenu('.J_cat_menu','#J_category1','.J_cat_menu','.J_cat_show_menu');
      <else />
          //二级分类
          $('.J_cat_menu').live('click',function() {
              var YTATADialog = $(this).dialog({
                  title: false,
                  loading: true,
                  footer: false,
                  header: false,
                  border: false,
                  backdrop: false
              });
              $.getJSON(ajaxURL, { act: "ajax_cat_list",type:3}, function(json){
                  if (json.status==0){
                      YTATADialog.hide();
                      disapperTooltip("remind", json.content);
                  }else if (json.status==1){
                      YTATADialog.hide();
                      var MDialog = $(this).dialog({
                          title: "请选择分类",
                          content:json.content,
                          footer: true,
                          header: true,
                          border: true,
                          innerPadding: true,
                          backdrop: true,
                          yes: function() {
                              cbtn=$(".ajax_cat_list span.select");
                              ctit=cbtn.attr('title');
                              category1=cbtn.attr('category1');
                              category2=cbtn.attr('category2');
                              if (ctit!='')
                              {
                                  $('.J_cat_menu').text(ctit);
                                  $('#J_category1').val(category1);
                                  $('#J_category2').val(category2);
                                  $('.modal').remove();
                                  $('.modal_backdrop').remove();
                              }

                          }
                      });
                      MDialog.setCloseDialog(false);
                  }else{
                      YTATADialog.hide();
                      disapperTooltip("remind","未知错误");
                  }
              });
          });

      </if>
      });
  </script>
  <script type="text/javascript">
      $(document).ready(function()
      {
          /********
           /#####
           /#####  TAG相关
           /#####
           */
//打开添加标签页JS操作 (ajax_tag_list.html页面操作)
          TAGnum=3;//允许TAG添加数量

//打开标签弹窗
          $('#J_addtag').live('click',function() {
              var YTATADialog = $(this).dialog({
                  title: false,
                  loading: true,
                  footer: false,
                  header: false,
                  border: false,
                  backdrop: false
              });

              tags=$(".showtag .tag");
              tags_str='';
              if (tags.length>0)
              {
                  tags_arr=new Array();
                  tags.each(function(i){
                      tags_arr[i]=$(this).attr('title');
                  });
                  tags_str=tags_arr.join("__yangtata__");
              }
              $.getJSON(ajaxURL, { act: "ajax_tag_list",tags:tags_str}, function(json){
                  if (json.status==0){
                      YTATADialog.hide();
                      disapperTooltip("remind", json.content);
                  }else if (json.status==1){
                      YTATADialog.hide();
                      var MDialog = $(this).dialog({
                          title: "请选择标签",
                          content:json.content,
                          footer: true,
                          header: true,
                          border: true,
                          innerPadding: true,
                          backdrop: true,
                          yes: function() {
                              tags=$(".ajax_tag_list .tagli.select");
                              if (tags.length>0)
                              {
                                  html='';
                                  tags.each(function(i){
                                      html+='<div class="tag" title="'+$(this).attr('title')+'">'+$(this).attr('title')+'<input name="tag[]" type="hidden" value="'+$(this).attr('title')+'"></div>';
                                  });
                                  $('.showtag .tag').remove();
                                  $('.showtag').prepend(html).show();
                                  unm=TAGnum-tags.length;
                                  $('.showtag .tip span').html(unm);
                              }

                          }
                      });
                  }else{
                      YTATADialog.hide();
                      disapperTooltip("remind","未知错误");
                  }
              });
          });
//从窗口选择标签
          $('.ajax_tag_list .tagli').live('click',function()
          {
              if ($(this).hasClass('select')){
                  $(this).removeClass('select');
              }else{
                  $(this).addClass('select');
              }
              if ($(".ajax_tag_list .tagli.select").length>TAGnum){
                  disapperTooltip("remind","最多只能选择"+TAGnum+"个标签");
                  $(this).removeClass('select');
              }
          });
//搜索标签
          $('.J_sotag_btn').live('click',function()
          {
              btn=$(this);
              btn.attr("disabled","disabled").addClass('btn_disabled');
              tagkey=$('#J_tagkey').val();
              if (tagkey.length==0)
              {
                  disapperTooltip("remind","请填写关键字！");
                  btn.removeAttr("disabled").removeClass('btn_disabled');
                  return false;
              }
              $.getJSON(ajaxURL,{act: "ajax_tag_so",tagkey:tagkey}, function(json){

                  if (json.status==0)
                  {
                      disapperTooltip("remind", json.content);
                      btn.removeAttr("disabled").removeClass('btn_disabled');
                  }
                  else if (json.status==1)
                  {
                      if (json.count==0)
                      {
                          $('.ajax_tag_list .soshow').hide();
                          $('.ajax_tag_list .soempty').show();
                          $(".ajax_tag_list .soempty strong").html(json.key);
                          $(".ajax_tag_list .soempty .J_add_tag_key").attr('title',json.key);
                      }
                      else
                      {
                          $('.ajax_tag_list .soshow').show();
                          $('.ajax_tag_list .soempty').hide();
                          tag=json.content;
                          htm='';
                          for(var i in tag)
                          {
                              htm+="<div class=\"tagli\" title=\""+tag[i].tag+"\">"+tag[i].tag+"</div>";
                          }
                          htm+="<div class=\"clear\"></div>";
                          $(".ajax_tag_list .soshow .stxt").html(htm);
                      }
                      btn.removeAttr("disabled").removeClass('btn_disabled');
                  }else{
                      disapperTooltip("remind","未知错误");
                      //
                      btn.removeAttr("disabled").removeClass('btn_disabled');
                      //
                  }
              });

          });
//从搜索结果添加标签
          $('.J_add_tag_key').live('click',function()
          {
              tag=$(this).attr('title');
              if ($(".ajax_tag_list .tagli[title='"+tag+"']").length>0)
              {
                  disapperTooltip("remind",tag+"已存在，不能重复添加标签");
                  return false;
              }
              else
              {
                  if ($(".ajax_tag_list .tagli.select").length>=TAGnum){
                      html="<div class=\"tagli\" title="+tag+">"+tag+"</div>";
                      $(".ajax_tag_list .tlist .clear").before(html);
                  }
                  else
                  {
                      html="<div class=\"tagli select\" title="+tag+">"+tag+"</div>";
                      $(".ajax_tag_list .tlist .clear").before(html);
                  }
              }
          });
//删除所选标签
          $('.showtag .tag').live('click',function()
          {
              $(this).remove();
              tags=$('.showtag .tag');
              if (tags.length==0)
              {
                  $('.showtag').hide();
              }
              unm=TAGnum-tags.length;
              $('.showtag .tip span').html(unm);
          });

      });
  </script>
  </body>
</html>
